package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.IsUserLoginAppBean;
import com.ymatou.iapi.userservice.service.IsUserLoginAppCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
/**
*用户是否登录过APP
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_IsUserLoginApp{
	private static IsUserLoginAppBean isuserloginappBean;
	private static IsUserLoginAppCall isuserloginappCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户是否登录过APP");
	}

	@Before
	public void caseUp() {
		isuserloginappBean=new IsUserLoginAppBean();
		isuserloginappCall=new IsUserLoginAppCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(isuserloginappCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_IsUserLoginApp_001() {
		Logger.start(true,"查询用户是否登录过APP,登入过,成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			regbean.setRegSource(0);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			int uid  = urrc.getUserid();
			JUserCallService.login(regbean.getLoginId(), regbean.getPas(),"1", regbean.getClientIp(), regbean.getDeviceId());
			isuserloginappBean.setUserId(uid);
			isuserloginappCall.setData(isuserloginappBean);
			isuserloginappCall.callService();			
			Logger.verifyEquals("true", isuserloginappCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", isuserloginappCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", isuserloginappCall.getString("ResponseCode"), "验证ResponseCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IsUserLoginApp_002() {
		Logger.start(true,"用户是app注册的,成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			regbean.setRegSource(1);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			int uid  = urrc.getUserid();
//			JUserCallService.login(regbean.getLoginId(), regbean.getPas(),"1", regbean.getClientIp(), regbean.getDeviceId());
			isuserloginappBean.setUserId(uid);
			isuserloginappCall.setData(isuserloginappBean);
			isuserloginappCall.callService();			
			Logger.verifyEquals("true", isuserloginappCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", isuserloginappCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", isuserloginappCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_IsUserLoginApp_003() {
		Logger.start(true,"用户不是app注册且没有登录记录,失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			regbean.setRegSource(0);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			int uid  = urrc.getUserid();
//			JUserCallService.login(regbean.getLoginId(), regbean.getPas(),"1", regbean.getClientIp(), regbean.getDeviceId());
			isuserloginappBean.setUserId(uid);
			isuserloginappCall.setData(isuserloginappBean);
			isuserloginappCall.callService();			
			Logger.verifyEquals("false", isuserloginappCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", isuserloginappCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", isuserloginappCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}